package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.AnalysisManageRightRole;
import com.hunttown.mes.rpc.domain.AnalysisManageRightRoleDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import com.hunttown.mes.rpc.exception.ConvertException;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2018-11-26 15:05:47
 */
public class AnalysisManageRightRoleConverts {

    private static Logger LOG = LoggerFactory.getLogger(AnalysisManageRightRoleConverts.class);

    public static List<AnalysisManageRightRoleDTO> convert(List<AnalysisManageRightRole> analysisManageRightRoleList) {
        if (CollectionUtils.isEmpty(analysisManageRightRoleList)) {
            return Collections.EMPTY_LIST;
        }

        List<AnalysisManageRightRoleDTO> analysisManageRightRoleListResult = Lists.newArrayList();
        for (AnalysisManageRightRole analysisManageRightRole : analysisManageRightRoleList) {
            analysisManageRightRoleListResult.add(convert(analysisManageRightRole));
        }
        return analysisManageRightRoleListResult;
    }

    public static AnalysisManageRightRoleDTO convert(AnalysisManageRightRole analysisManageRightRole) {
        try {
            return BeanUtils.copy(analysisManageRightRole, AnalysisManageRightRoleDTO.class);
        } catch (Exception e) {
            LOG.error("AnalysisManageRightRole到AnalysisManageRightRoleDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "AnalysisManageRightRole到AnalysisManageRightRoleDTO转换失败", e);
        }
    }

    public static AnalysisManageRightRole convert(AnalysisManageRightRoleDTO analysisManageRightRoleDTO) {
        try {
            return BeanUtils.copy(analysisManageRightRoleDTO, AnalysisManageRightRole.class);
        } catch (Exception e) {
            LOG.error("AnalysisManageRightRoleDTO到AnalysisManageRightRole转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "AnalysisManageRightRoleDTO到AnalysisManageRightRole转换失败", e);
        }
    }
}